package com.openarena.other.suggestions;

import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Logger;

public class Suggestion {

    private static final Logger logger = Logger.getLogger(Suggestion.class.getCanonicalName());
    private String text;
    private String title;
    private String ip;
    private final Date dateCreated;

    public Suggestion() {
        dateCreated = new Date();
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Date getDateCreated() {
        return dateCreated;
    }
    private static final String ISO8601DateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'";

    public void saveToDisk() throws IOException {
        FileWriter fw = null;
        try {
            fw = new FileWriter("/home/gmarcone/Descargas/openarena_logs/suggestions/" + new SimpleDateFormat(ISO8601DateFormat).format(dateCreated));

            fw.write("By: ");
            fw.write(ip);
            fw.write(System.getProperty("line.separator"));

            fw.write("Title: ");
            fw.write(title);
            fw.write(System.getProperty("line.separator"));

            fw.write("Text: " + System.getProperty("line.separator"));
            fw.write(text);
            fw.write(System.getProperty("line.separator"));

        } finally {
            if (fw != null) {
                fw.flush();
                fw.close();
            }
        }
    }
}
